<template>
	<view class="content">
		<view v-show="show1">
			<view class="top">
				<img src="/static/wash.png" alt="">
				<view class="title">正在清洗</view>
				<view class="canshu">
					<view>已选择模式：标准洗衣
						<view class="text">
							<text>
								{{detail.times}}小时
							</text>
						</view>
					</view>
					<view>剩余时长（分）
						<view class="text">
							<u-count-down :time="timestamp" format="HH:mm:ss" autoStart millisecond @change="onChange">
								<view class="time">
									<text class="time__item">{{ timeData.days }}&nbsp;天</text>
									<text
										class="time__item">{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}&nbsp;时</text>
									<text class="time__item">{{ timeData.minutes }}&nbsp;分</text>
									<text class="time__item">{{ timeData.seconds }}&nbsp;秒</text>
								</view>
							</u-count-down>
						</view>
					</view>

				</view>
			</view>
			<view class="info">
				<view class="item">
					<view class="info">
						<view class="title">{{detail.dpcinfo.title}}</view>
						<text>洗衣机编号：{{detail.dpnum}}</text>
						<text>洗衣时间：{{detail.start}} - {{detail.end}}</text>
						<text>洗衣机地址：{{detail.dpcinfo.address}}</text>
					</view>

				</view>
			</view>
			<view class="jieshu" @tap="endcd">
				结束清洗
			</view>
		</view>
		<view v-show="show2" style="margin-top: 50%;">
			<u-empty mode="order" text="当前无进行中的订单">
			</u-empty>
			<view class="gtobak" @tap="gtobak">
				返回个人中心
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	let that
	export default {
		data() {
			return {
				timeData: {},
				detail: {
						times: 1,
						start: '10:00:00',
						end: '11:00:00',
						sy_time: 3600,
						dpcinfo: {
							title: '测试洗衣机',
							address: '测试地址'
						},
						dpnum: '123456',
						
				},
				timestamp: 0,
				show1: true,
				show2: false
			}
		},
		onShow() {
			// this.getdetail()
		},
		mounted() {
			that = this
		},
		computed: {
			//引入store全局变量
			...mapState(['loginState', 'userInfo'])
		},
		methods: {
			onChange(e) {
				this.timeData = e
			},
			getdetail() {
				this.$http_api.orderdetail({
					uid: this.userInfo.id
				}).then((res) => {
					if (res.code == 2) {
						that.show1 = false
						that.show2 = true
					}
					that.detail = res
					that.timestamp = res.sy_time
				})
			},
			//结束订单
			endcd() {
				uni.showModal({
					title: '结束订单',
					content: '请确认是否结束洗衣',
					success: function(res) {
						if (res.confirm) {
							that.$http_api.endorder({
								uid: that.userInfo.id
							}).then((res) => {
								setTimeout(function(){
									uni.redirectTo({
										url:'/pages/order/order-detail'
									})
								},2000)
							})
						}
					}
				})

			},
			gtobak(){
				uni.switchTab({
					url:'/pages/user/user'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		padding: 0 3%;
		box-sizing: border-box;
	}

	.top {
		padding-top: 80rpx;
		margin-bottom: 40rpx;
		text-align: center;
		padding-bottom: 40rpx;
		border-bottom: 1px solid #ccc;

		img {
			width: 200rpx;
			height: 200rpx;
			margin-bottom: 40rpx;
			border: 5px solid #23BF61;
			padding: 40rpx;
			border-radius: 100%;
		}

		.title {
			margin-bottom: 50rpx;
			font-weight: bold;
		}

		.date {
			font-size: 28rpx;
			color: #666;
			margin-bottom: 60rpx;
		}

		.canshu {
			display: flex;
			justify-content: space-between;
			width: 100%;
			margin: 0 auto;

			view {
				font-size: 26rpx;
				color: #666;

				text {
					display: block;
					font-size: 32rpx;
					font-weight: bold;
					color: #333;
					margin-top: 10rpx;
				}

			}

			.time {
				display: flex;
			}
		}

	}

	.item {
		background: #fff;
		padding: 20rpx;
		margin-bottom: 40rpx;
		border-radius: 10rpx;

		.info {
			// background: url("../../static/cd.png") no-repeat right;
			background-size: 28px;
			background-position-y: 0;

			.title {
				font-size: 31rpx;
				font-weight: 600;
				margin-bottom: 20rpx;
			}

			text {
				font-size: 28rpx;
				display: block;
				color: #666;
				margin-top: 20rpx;
			}
		}
	}

	.jieshu {
		width: 300rpx;
		padding: 20rpx 0;
		border-radius: 40rpx;
		background: #23BF61;
		color: #fff;
		text-align: center;
		margin: 90rpx auto 0;
	}
	
	.gtobak{
		width: 280rpx;
		padding: 15rpx 0;
		border-radius: 40rpx;
		background: #23BF61;
		color: #fff;
		text-align: center;
		margin: 90rpx auto 0;
		font-size: 28rpx;
	}
</style>